import { useState } from "react";

// 封装成函数以后，还可以进行代码的复用
const useCount = (num) => {
  // 将相同功能的代码进行聚合，方便维护
  const [count, setCount] = useState(num);
  const add = () => {
    setCount((v) => v + 1);
  };
  const minus = () => {
    setCount((v) => v - 1);
  };
  return [count, add, minus];
};

export default useCount;
